<template>
  <div>
    <a-button type="primary" @click="exportData"><i class="fa fa-file-excel-o mr5"></i>导出</a-button>
  </div>
</template>

<script>
import ExportJsonExcel from 'js-export-excel'
export default {
  props: {
    fileName: {
      type: String,
      default: '页面导出Excel例子'
    },
    sheetName: {
      type: String,
      default: 'sheet'
    },
    sheetData: {
      type: Array,
      default: () => {
        return [{ name: '张三', sex: '男', age: 11 }, { name: '李四', sex: '男', age: 13 }]
      }
    },
    sheetFilter: {
      type: Array,
      default: () => {
        return ['name', 'sex', 'age']
      }
    },
    sheetHeader: {
      type: Array,
      default: () => {
        return ['姓名', '性别', '年龄']
      }
    }
  },
  data () {
    return {
    }
  },
  methods: {
    exportData () {
      var option = {}
      option.fileName = this.fileName
      option.datas = [
        {
          sheetData: this.sheetData,
          sheetName: this.sheetName,
          sheetFilter: this.sheetFilter,
          sheetHeader: this.sheetHeader
        }
      ]
      const excel = new ExportJsonExcel(option)
      excel.saveExcel()
    }
  }
}
</script>
<style lang="less" scoped>
</style>
